#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
const int MAXN=1e6+10;
char a[MAXN];
int n,nxt[MAXN];
void cal_nxt()
{
	int k=-1;
	nxt[0]=-1;
	for(int i=1;i<n;++i)
	{
		while(~k&&a[k+1]!=a[i])k=nxt[k];
		if(a[k+1]==a[i])++k;
		nxt[i]=k;
	}
	return;
}
int main()
{
	int T=read();
	while(T--)
	{
		scanf("%s",a);
		n=strlen(a);
		cal_nxt();
		int ans=n-nxt[n-1]-1;
		(n%ans)?puts("1"):printf("%d\n",n/ans);
	}
	return 0;
}
